home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Produtividade / Software2 / Product4 / Setup.exe / drupal-4.6.0 / modules / ping.module < prev    next >
Encoding:
Text File  |  2005-04-01  |  2.1 KB  |  71 lines

  1. <?php
  2. // $Id: ping.module,v 1.29 2005/04/01 15:55:00 dries Exp $
  3.  
  4. /**
  5.  * @file
  6.  * Alerts other sites that your site has been updated.
  7.  */
  8.  
  9. /**
  10.  * Implementation of hook_help().
  11.  */
  12. function ping_help($section) {
  13.   switch ($section) {
  14.     case 'admin/help#ping':
  15.       $output .= t("
  16.       <p>Drupal can automatically send notifications (called \"pings\") to the %pingomatic to tell them that your site has changed.  In turn pingomatic.com will ping other services like weblogs.com, Technorati, blo.gs, BlogRolling, Feedster.com, Moreover, etc.</p>
  17.       <p>The ping feature requires crontab.</p>", array('%pingomatic' => '<a href="http://pingomatic.com/">http://pingomatic.com/</a>'));
  18.       break;
  19.  
  20.     case 'admin/modules#description':
  21.       $output = t('Alerts other sites when your site has been updated.');
  22.       break;
  23.   }
  24.  
  25.   return $output;
  26. }
  27.  
  28. /**
  29.  * Implementation of hook_cron().
  30.  *
  31.  * Fire off notifications of updates to remote sites.
  32.  */
  33. function ping_cron() {
  34.   global $base_url;
  35.  
  36.   if (variable_get('site_name', 0) && variable_get('site_slogan', 0)) {
  37.     if (db_num_rows(db_query("SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 AND (created > '". variable_get('ping_cron_last', time()) ."' OR changed > '". variable_get('ping_cron_last', time()) ."')"), 1)) {
  38.       _ping_notify(variable_get('site_name', '') .' - '. variable_get('site_slogan', ''), $base_url);
  39.     }
  40.  
  41.     variable_set('ping_cron_last', time());
  42.   }
  43. }
  44.  
  45. /**
  46.  * Call hook_ping() in all modules to notify remote sites that there is
  47.  * new content at this one.
  48.  */
  49. function _ping_notify($name, $url) {
  50.   module_invoke_all('ping', $name, $url);
  51. }
  52.  
  53. /**
  54.  * Implementation of hook_ping().
  55.  *
  56.  * Notifies pingomatic.com, blo.gs, and technorati.com of changes at this site.
  57.  */
  58. function ping_ping($name = '', $url = '') {
  59.  
  60.   $feed = url('node/feed', NULL, NULL, TRUE);
  61.   $client = new xmlrpc_client('/', 'rpc.pingomatic.com', 80);
  62.   $message = new xmlrpcmsg('weblogUpdates.ping', array(new xmlrpcval($name), new xmlrpcval($url)));
  63.   $result = $client->send($message);
  64.  
  65.   if (!$result || $result->faultCode()) {
  66.     watchdog('directory ping', t('Failed to notify pingomatic.com (site).'), WATCHDOG_WARNING);
  67.   }
  68. }
  69.  
  70. ?>
  71.